<template>
  <div class="page-content"><h2>重新获取access_token</h2>
    <p>
      access_token的有效期目前为24个小时，过期需要重新获取。如果实验时间超过24小时，请在学生完成实验后向平台返回实验成绩时，重新获取新的access_token。</p>
    <p class="text-danger">
      注意：调用此接口获取的access_token，不支持再次通过此接口获取新的access_token，原access_token最多可有2次机会获取新的access_token。</p>
    <p><strong>接口调用请求说明</strong></p>
    <p>http请求方式：POST/GET <a href="javascript:">{{ addr }}/oauth/token/refreshtoken?refresh_token=ACCESS_TOKEN&amp;appid=APPID&amp;signature=SIGNATURE</a>
    </p>
    <p><strong>请求示例</strong></p>
    <p><strong>参数说明</strong></p>
    <div class="table-ctn">
      <table>
        <thead>
          <tr>
            <th>参数</th>
            <th>说明</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>appid</td>
            <td>由“平台”分配给各实验平台的唯一编号</td>
          </tr>
          <tr>
            <td>signature</td>
            <td><p>MD5(ACCESS_TOKEN+APPID+SECRET)</p>
              <p>注：</p>
              <p>signature编码后需要改成全部大写字母</p>
              <p>ACCESS_TOKEN是接口调用凭证</p>
              <p>APPID是由“平台”分配给各实验平台的唯一编号</p>
              <p>SECRET是由“平台”分配给各实验平台的密钥</p></td>
          </tr>
          <tr>
            <td><span style="color: red">refresh_token</span></td>
            <td>调用“获取用户信息”接口时返回的<span style="color: red">refresh_token</span>。注意。</td>
          </tr>
        </tbody>
      </table>
    </div>
    <p><strong>调用URL示例</strong></p>
    <p>
      {{ addr }}/oauth/token/refreshtoken?<span style="color: red">refresh_token</span>=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtc2ciOiLosIPnlKjmiJDlip_vvIzov5Tlm57miYDpnIDmlbDmja4iLCJjb2RlIjowLCJjcmVhdGVfdGltZSI6MTcxMTEwMzIyOTEyMiwiY3JlYXRlX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjIgMTg6Mjc6MDkiLCJ1c2VyX25hbWUiOiIxNzAxODA4MTY5NzkzMTM4NjkwIiwiYXV0aG9yaXRpZXMiOlsiQURNSU4iXSwiY2xpZW50X2lkIjoiMTY4MTYwMDIyMjc0ODI0MTkyOSIsImRpcyI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJzY29wZSI6WyJjYWxsYmFjazpzY29yZSJdLCJhdGkiOiJhNTdhYjk5Yy02ZWQzLTRiOTMtYThhMy0wNzc0NjQzNGZmZTgiLCJleHBpcmVzX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjMgMTg6Mjc6MDgiLCJ1biI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJleHAiOjE3MTM2OTUyMjksImp0aSI6ImE3YTUwYzdmLTMxN2MtNGUzYy1iNTIwLWViZDhiMDI2ZmVjZiIsImV4cGlyZXNfdGltZSI6MTcxMTE4OTYyODEyMn0.CCIavimTmuyBcy6LxP9GHJHZSfurR9ILjhg-N2b9e48&amp;<span style="color: red">appid</span>=1681600222748241929&amp;<span style="color: red">signature</span>=8DF4809E7E2FE82C0D1BD495940A5D76</p>
    <p><strong>返回结果</strong></p>
    <p>正确时的返回JSON数据包如下：</p>
    <pre><code>{
    <span class="key">"code":</span> <span class="number">0</span>,
    <span class="key">"msg":</span> <span class="string">"调用成功，返回所需数据"</span>,
    <span class="key">"access_token":</span> <span class="string">"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtc2ciOiLosIPnlKjmiJDlip_vvIzov5Tlm57miYDpnIDmlbDmja4iLCJjb2RlIjowLCJjcmVhdGVfdGltZSI6MTcxMTExMTMxMzk0MSwiY3JlYXRlX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjIgMjA6NDE6NTMiLCJ1c2VyX25hbWUiOiIxNzAxODA4MTY5NzkzMTM4NjkwIiwiYXV0aG9yaXRpZXMiOlsiQURNSU4iXSwiY2xpZW50X2lkIjoiMTY4MTYwMDIyMjc0ODI0MTkyOSIsImRpcyI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJzY29wZSI6WyJjYWxsYmFjazpzY29yZSJdLCJleHBpcmVzX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjMgMjA6NDE6NTIiLCJ1biI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJleHAiOjE3MTExOTc3MTMsImp0aSI6IjhhN2VlOGQ4LTdhMTUtNDU1OS1iNjc4LTI1NWFhYWNjMzI5MCIsImV4cGlyZXNfdGltZSI6MTcxMTE5NzcxMjk0MX0.zJaOYnkf9-dr1KVk7NwnA2Tr3Tq3F6vmR-i6zqY2yxg"</span>,
    <span class="key">"token_type":</span> <span class="string">"bearer"</span>,
    <span class="key">"refresh_token":</span> <span class="string">"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtc2ciOiLosIPnlKjmiJDlip_vvIzov5Tlm57miYDpnIDmlbDmja4iLCJjb2RlIjowLCJjcmVhdGVfdGltZSI6MTcxMTExMTMxMzk0MSwiY3JlYXRlX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjIgMjA6NDE6NTMiLCJ1c2VyX25hbWUiOiIxNzAxODA4MTY5NzkzMTM4NjkwIiwiYXV0aG9yaXRpZXMiOlsiQURNSU4iXSwiY2xpZW50X2lkIjoiMTY4MTYwMDIyMjc0ODI0MTkyOSIsImRpcyI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJzY29wZSI6WyJjYWxsYmFjazpzY29yZSJdLCJhdGkiOiI4YTdlZThkOC03YTE1LTQ1NTktYjY3OC0yNTVhYWFjYzMyOTAiLCJleHBpcmVzX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjMgMjA6NDE6NTIiLCJ1biI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJleHAiOjE3MTM2OTUyMjksImp0aSI6ImE3YTUwYzdmLTMxN2MtNGUzYy1iNTIwLWViZDhiMDI2ZmVjZiIsImV4cGlyZXNfdGltZSI6MTcxMTE5NzcxMjk0MX0.rEMrYX8b3krT1v_ADEyWB3MJC9nDLULniEK-6WU0s5w"</span>,
    <span class="key">"expires_in":</span> <span class="number">86399</span>,
    <span class="key">"scope":</span> <span class="string">"callback:score"</span>,
    <span class="key">"un":</span> <span class="string">"1701808169793138690"</span>,
    <span class="key">"dis":</span> <span class="string">"1701808169793138690"</span>,
    <span class="key">"create_time":</span> <span class="string">"1711111313941"</span>,
    <span class="key">"create_time_display":</span> <span class="string">"2024-03-22 20:41:53"</span>,
    <span class="key">"expires_time":</span> <span class="string">"1711197712941"</span>,
    <span class="key">"expires_time_display":</span> <span class="string">"2024-03-23 20:41:52"</span>,
    <span class="key">"jti":</span> <span class="string">"8a7ee8d8-7a15-4559-b678-255aaacc3290"</span>
}</code></pre>
    <p><strong>返回数据说明：</strong></p>
    <div class="table-ctn">
      <table>
        <thead>
          <tr>
            <th>参数</th>
            <th>说明</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>access_token</td>
            <td>接口调用凭证</td>
          </tr>
          <tr>
            <td>create_time</td>
            <td>access_token创建时间，13位时间戳</td>
          </tr>
          <tr>
            <td>create_time_display</td>
            <td>示例：2020-08-24 08:54:21</td>
          </tr>
          <tr>
            <td>expires_time</td>
            <td>过期时间，13位时间戳</td>
          </tr>
          <tr>
            <td>expires_time_display</td>
            <td>示例：2020-08-24 10:54:21</td>
          </tr>
        </tbody>
      </table>
    </div>
    <p />
    <p>错误时的返回JSON数据包如下（示例为参数缺失）：</p>
    <pre><code>{
    <span class="key">"code":</span> <span class="number">1</span>,
    <span class="key">"msg":</span> <span class="string">"参数错误"</span>
}</code></pre>
    <p><strong>返回码说明：</strong></p>
    <div class="table-ctn">
      <table>
        <thead>
          <tr>
            <th>返回码</th>
            <th>说明</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>0</td>
            <td>调用成功，返回所需数据</td>
          </tr>
          <tr>
            <td>1</td>
            <td>参数错误：access_token缺失/appid缺失/signature缺失</td>
          </tr>
          <tr>
            <td>2</td>
            <td>密钥错误：signature不匹配。请注意签名时如有encode参数，均需要decode解码处理</td>
          </tr>
          <tr>
            <td>3</td>
            <td>无效access_token</td>
          </tr>
          <tr>
            <td>4</td>
            <td>原始access_token不正确</td>
          </tr>
          <tr>
            <td>5</td>
            <td>请重新获取access_token（重新获取次数超出2次）</td>
          </tr>
          <tr>
            <td>其他值</td>
            <td>非法请求或系统错误</td>
          </tr>
        </tbody>
      </table>
    </div>
    <p />
    <p><strong>Python示例</strong></p>
    <pre><code>import json<br>from urllib.parse import quote, unquote<br>import urllib3<br>import hashlib<br><br>http = urllib3.PoolManager()<br>def re_access_token():<br>    APPID = '1681600222748241929'<br>    SECRET = '123456='<br>    API_PATH = '{{ addr }}'<br><br>    # 此处是使用上一步获取到的ACCESS_TOKEN原文，无需解码<br>     ACCESS_TOKEN= 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtc2ciOiLosIPnlKjmiJDlip_vvIzov5Tlm57miYDpnIDmlbDmja4iLCJjb2RlIjowLCJjcmVhdGVfdGltZSI6MTcxMTEwMzIyOTEyMiwiY3JlYXRlX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjIgMTg6Mjc6MDkiLCJ1c2VyX25hbWUiOiIxNzAxODA4MTY5NzkzMTM4NjkwIiwiYXV0aG9yaXRpZXMiOlsiQURNSU4iXSwiY2xpZW50X2lkIjoiMTY4MTYwMDIyMjc0ODI0MTkyOSIsImRpcyI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJzY29wZSI6WyJjYWxsYmFjazpzY29yZSJdLCJhdGkiOiJhNTdhYjk5Yy02ZWQzLTRiOTMtYThhMy0wNzc0NjQzNGZmZTgiLCJleHBpcmVzX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjMgMTg6Mjc6MDgiLCJ1biI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJleHAiOjE3MTM2OTUyMjksImp0aSI6ImE3YTUwYzdmLTMxN2MtNGUzYy1iNTIwLWViZDhiMDI2ZmVjZiIsImV4cGlyZXNfdGltZSI6MTcxMTE4OTYyODEyMn0.CCIavimTmuyBcy6LxP9GHJHZSfurR9ILjhg-N2b9e48'<br>    text = ACCESS_TOKEN + APPID + SECRET<br>    hl = hashlib.md5()<br>    hl.update(text.encode(encoding='utf8'))<br>    signature = hl.hexdigest().upper()<br><br>    # 此处是在url中使用ACCESS_TOKEN 需要对ACCESS_TOKEN进行url编码<br>    path = API_PATH + '/oauth/token/refreshtoken?refresh_token=' + quote(ACCESS_TOKEN) + '&amp;appid=' + APPID + '&amp;signature=' + signature<br>    r = http.request("GET", path)<br>    return json.loads(r.data.decode('utf-8'))['access_token']<br><br><br>if __name__ == '__main__':<br>    ACCESS_TOKEN = re_access_token()<br>    print(ACCESS_TOKEN)<br></code></pre>
    <p><strong>Python示例运行结果</strong></p>
    <p />
    <pre>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtc2ciOiLosIPnlKjmiJDlip_vvIzov5Tlm57miYDpnIDmlbDmja4iLCJjb2RlIjowLCJjcmVhdGVfdGltZSI6MTcxMTExMTMxMzk0MSwiY3JlYXRlX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjIgMjA6NDE6NTMiLCJ1c2VyX25hbWUiOiIxNzAxODA4MTY5NzkzMTM4NjkwIiwiYXV0aG9yaXRpZXMiOlsiQURNSU4iXSwiY2xpZW50X2lkIjoiMTY4MTYwMDIyMjc0ODI0MTkyOSIsImRpcyI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJzY29wZSI6WyJjYWxsYmFjazpzY29yZSJdLCJleHBpcmVzX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjMgMjA6NDE6NTIiLCJ1biI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJleHAiOjE3MTExOTc3MTMsImp0aSI6IjhhN2VlOGQ4LTdhMTUtNDU1OS1iNjc4LTI1NWFhYWNjMzI5MCIsImV4cGlyZXNfdGltZSI6MTcxMTE5NzcxMjk0MX0.zJaOYnkf9-dr1KVk7NwnA2Tr3Tq3F6vmR-i6zqY2yxg</pre>
    <p />
    <p />
    <p><strong>特别说明</strong></p>
    <p>1.接口支持前端语言Javascript使用。<a href="javascript:;" @click="downloadApi">《jquery 调用示例》</a></p>
    <p>2.请注意签名时如有encode参数，均需要decode解码处理。</p>
  </div>
</template>
<script>
export default {
  data() {
    return {
      addr: ''
    }
  },
  mounted() {
    if (process.client) {
      this.addr = window.location.protocol + '//' + window.location.hostname + ':8180'
    }
  },
  methods: {
    downloadApi() {
      window.open(this.addr + '/jquery-api.html', '_blank')
      return false
    }
  }
}
</script>
